#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <math.h>
int Close_sum(int arr[], int n, int sum)
{
	int left = 0;
	int right = n - 1;
	int ret = 0;
	while (left < right)
	{
		ret = arr[left] + arr[right];
		if (ret == sum)
			return ret;
		if (ret > sum)
		{
			right--;
			if (abs(arr[left] + arr[right] - sum) > abs(ret - sum))
				return ret;
		}
		if (ret < sum)
		{
			left++;
			if (abs(arr[left] + arr[right] - sum) > abs(ret - sum))
				return ret;
		}
	}
	return ret;
}

int main()
{
	int arr[] = { 2,3,4,6,9,22,55,85,256,523 };
	int sum;
	int sz = sizeof(arr) / sizeof(arr[0]);
	scanf("%d", &sum);
	int close = Close_sum(arr, 10, sum);
	printf("%d\n", close);
	return 0;
}